package com.wzh.mall.auth.config;

import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @program: mall
 * @description: session的一些配置类  整合  作用域扩大  改变序列化机制
 * @author: Mr.Wang
 * @create: 2021-10-08 18:52
 **/
@Configuration
public class MallSessionConfig {


    /**
      * @Description: 扩大作用域 所有子域的session作用域整合到父域中去
      * @Param: []
      * @return: org.springframework.session.web.http.CookieSerializer
      * @Author: Mr.Wang
      * @Date: 2021/10/8
      * @Time: 18:55
      */

    @Bean
    public CookieSerializer cookieSerializer(){

        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();

        //指定方法作用域
        defaultCookieSerializer.setDomainName("mall.com");
        // 指定session的名字
        defaultCookieSerializer.setCookieName("MALLSESSION");


        return defaultCookieSerializer;
    }


    /**
      * @Description: 改变序列化方式  使用json序列化机制
      * @Param: None
      * @return: org.springframework.data.redis.serializer.RedisSerializer<java.lang.Object>
      * @Author: Mr.Wang
      * @Date: 2021/10/8
      * @Time: 18:58
      */

    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericFastJsonRedisSerializer();
    }



}
